# ===============================================================#
#                     Replication files for:                     #
#.  "Attitudinal and Behavioral Legacies of Wartime Violence:    #
#                      A Meta-Analysis"                          #
#                        Joan Barceló                            #
#               American Political Science Review                #
#               Last update: September 3, 2025                   #
# ===============================================================#

#################################
# Table E.1: Predicting Number of Studies
################################

# Libraries
library(lmtest)
library(sandwich)
library(stargazer)

## ------------------------ Load data ------------------------

model_data <- haven::read_dta("~/Auxiliary/model_data.dta")

# 1. Continuous DV

# Model 1.1: Conflict fundamentals only, v1
m_cont0 <- lm(num_studies ~ as.factor(type_of_conflict) + conflict_duration + I(2023-year_last), data = model_data)

# Model 1.2: Conflict fundamentals only, .v2
m_cont1 <- lm(num_studies ~ as.factor(type_of_conflict) + I(2023-year_last) + 
                total_bd_best_10k, data = model_data)

# Model 2: Conflict fundamentals + country controls
m_cont2 <- lm(num_studies ~ as.factor(type_of_conflict) + conflict_duration  + I(2023-year_last) + 
                total_bd_best_10k + gdp_pc_1000 + 
                wgi_estimate + polity2 + english_battle_location, data = model_data)

# Model 3: Conflict fundamentals + country controls + region dummies
m_cont3 <- lm(num_studies ~ as.factor(type_of_conflict) + conflict_duration  + I(2023-year_last) + 
                total_bd_best_10k + gdp_pc_1000 + 
                wgi_estimate + polity2 + english_battle_location + 
                region_me + region_africa + region_asia, data = model_data)

# 2. Binary DV (Logit)
m_logit0 <- glm(num_studies_bin ~ as.factor(type_of_conflict) + conflict_duration + I(2023-year_last), family = binomial, data = model_data)
m_logit1 <- glm(num_studies_bin ~ as.factor(type_of_conflict) + I(2023-year_last) + 
                  total_bd_best_10k, family = binomial, data = model_data)
m_logit2 <- glm(num_studies_bin ~  as.factor(type_of_conflict) + conflict_duration  + I(2023-year_last) + 
                  total_bd_best_10k + gdp_pc_1000 + 
                  wgi_estimate + polity2 + english_battle_location, family = binomial, data = model_data)
m_logit3 <- glm(num_studies_bin ~ as.factor(type_of_conflict) + conflict_duration  + I(2023-year_last) + 
                  total_bd_best_10k + gdp_pc_1000 + 
                  wgi_estimate + polity2 + english_battle_location + 
                  region_me + region_africa + region_asia, family = binomial, data = model_data)

# OLS block, continuous DV: log(Number of Studies + 1)
stargazer(m_cont0, m_cont1, m_cont2, m_cont3,
          type = "text",
          dep.var.caption = "Continuous Dependent Variable: (OLS)",
          dep.var.labels  = "Number of Studies (log)",
          column.labels   = c("(1)", "(2)", "(3)", "(4)"),
          covariate.labels = c("Intrastate Conflict", "Internationalized Conflict",
                               "Conflict Duration", "Years Since Last Event",
                               "Total Battle Deaths ('0000)", "GDP per capita ('000)",
                               "Governance (WGI)", "Polity2", "English Battle Location",
                               "Middle East", "Africa", "Asia"),
          omit.stat = c("f", "ser"),
          digits = 2,
          star.cutoffs = c(0.05, 0.01, 0.001),
          star.char = c("*", "**", "***"),
          notes = "")

# Logit block, binary DV: any study 0 or 1
stargazer(m_logit0, m_logit1, m_logit2, m_logit3,
          type = "text",
          dep.var.caption = "Binary Dependent Variable: (Logit)",
          dep.var.labels  = "Conflict Studied (0/1)",
          column.labels   = c("(5)", "(6)", "(7)", "(8)"),
          covariate.labels = c("Intrastate Conflict", "Internationalized Conflict",
                               "Conflict Duration", "Years Since Last Event",
                               "Total Battle Deaths ('0000)", "GDP per capita ('000)",
                               "Governance (WGI)", "Polity2", "English Battle Location",
                               "Middle East", "Africa", "Asia"),
          omit.stat = c("f", "ser"),
          digits = 2,
          star.cutoffs = c(0.05, 0.01, 0.001),
          star.char = c("*", "**", "***"),
          notes = "")

